package spark;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@SpringBootApplication
@RestController
public class SparkHttpSubmitProxyApplication {


    @Autowired
    JdbcTemplate jdbcTemplate;


    public static void main(String[] args) {
        SpringApplication.run(SparkHttpSubmitProxyApplication.class, args);
    }


    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public Object submit(){
        String id = UUID.randomUUID().toString();
        long start = System.currentTimeMillis();
        String sql = "INSERT INTO jobs (id, master, applicationId, driverId, status, statusSparkMaster, statusYarnMaster, startTime, endTime, logPath) VALUES ('"+id+"', 'Master', 'applicationId', 'driverId', 'status', 'statusSparkMaster', 'statusyarnMaster', '"+start+"', '"+(start + 1000)+"', '/path')";
        jdbcTemplate.update(sql);

        List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from jobs ORDER BY startTime DESC limit 10");
        return list;
    }

}
